]>
Commit | Line | Data |
---|---|---|
77d0155b | 1 | import Combine |
5e8ff485 RBR |
2 | import CoreData |
3 | import CoreGraphics | |
4 | import SwiftUI | |
5 | ||
6 | struct MapRenderView: View { | |
7 | ||
e2c37ac1 | 8 | @Binding var document: MapDocument |
fdb4633d | 9 | @Binding var evolution: StageType |
e2c37ac1 | 10 | |
fdb4633d RBR |
11 | var stage: Stage { |
12 | Stage.stages(evolution) | |
13 | } | |
75a0e450 | 14 | |
e2c37ac1 RBR |
15 | var parsedMap: ParsedMap { |
16 | MapParser.parse(content: document.text) | |
17 | } | |
5e8ff485 | 18 | |
e2c37ac1 RBR |
19 | let mapSize = Dimensions.mapSize |
20 | let padding = Dimensions.mapPadding | |
5e8ff485 | 21 | |
fdb4633d | 22 | let lineWidth = CGFloat(0.5) |
5e8ff485 | 23 | let vertexSize = CGSize(width: 25.0, height: 25.0) |
e2c37ac1 RBR |
24 | |
25 | var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in } | |
5e8ff485 | 26 | |
5e8ff485 RBR |
27 | var body: some View { |
28 | ZStack(alignment: .topLeading) { | |
29 | ||
30 | Path { path in | |
31 | path.addRect( | |
32 | CGRect( | |
33 | x: -padding, y: -padding, width: mapSize.width + padding * 2, | |
77d0155b | 34 | height: mapSize.height + padding * 4)) |
fdb4633d | 35 | }.fill(.white) |
5e8ff485 RBR |
36 | |
37 | MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages) | |
38 | MapAxes( | |
fdb4633d RBR |
39 | mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages) |
40 | MapEdges( | |
41 | mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges) | |
42 | MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers) | |
e2c37ac1 RBR |
43 | MapVertices( |
44 | mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices, | |
45 | onDragVertex: onDragVertex) | |
5e8ff485 RBR |
46 | MapOpportunities( |
47 | mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, | |
48 | opportunities: parsedMap.opportunities) | |
e2c37ac1 RBR |
49 | MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup( |
50 | opaque: true | |
51 | ).opacity(0.1) | |
fdb4633d RBR |
52 | MapNotes( |
53 | mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes) | |
e2c37ac1 RBR |
54 | }.offset(x: padding, y: padding).frame( |
55 | width: mapSize.width + 2 * padding, | |
77d0155b | 56 | height: mapSize.height + 2 * padding, alignment: .topLeading |
e2c37ac1 | 57 | ) |
5e8ff485 RBR |
58 | } |
59 | } | |
60 | ||
e2c37ac1 RBR |
61 | #Preview { |
62 | MapRenderView( | |
63 | document: Binding.constant(MapDocument(text: "")), | |
64 | evolution: Binding.constant(StageType.general) | |
65 | ) | |
5e8ff485 | 66 | } |